﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="NotificationHistoryByDates.aspx.cs" Inherits="GPSTrackingWebsiteManager.Pages.NotificationHistoryByDates" %>

<!DOCTYPE html>

<link href="../../Css/GPSTrackingWebsite.css" rel="stylesheet" />
<link href="../../Css/messi.css" rel="stylesheet" />
<script src="../../Javascript/jquery-1.11.1.min.js"></script>
<script src="../../Javascript/messi.js"></script>
<script src="../../Javascript/Custom.js"></script>
<script src="../../Javascript/WindowMessageManager.js"></script>
<script src="../../Javascript/ObjectsV2.js"></script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
    <script type="text/javascript">

        //Windows Message Manager 
        var objWindowsMessageManager = new WindowsMessageManager();        

        var opener = GetRadWindow();
        var NotificationHistory = new NotificationHistory();

        function GetRadWindow() {
            var oWindow = null;
            if (window.radWindow)
                oWindow = window.radWindow;
            else if (window.frameElement.radWindow)
                oWindow = window.frameElement.radWindow;
            return oWindow.BrowserWindow;
        }

        function getNotifications() {
            if (NotificationHistory.isValidToGetNotifications(opener, getFormatDate(getBeginDateSelected().get_textBox().value), getFormatDate(getEndDateSelected().get_textBox().value)))
            {
                getAllNotificationsByGPSImeiAndDate();
            }
        }

        function getAllNotificationsByGPSImeiAndDate() {
            requestStart(getrpvNotificationsPanelUpdateControl());
            PageMethods.wsGetAllNotificationsByGPSImeiAndDate(opener.globalGPSImei.imeiSelected, getFormatDate(getBeginDateSelected().get_textBox().value), getFormatDate(getEndDateSelected().get_textBox().value), getAllNotificationsByGPSImeiAndDateOk, getAllNotificationsByGPSImeiAndDateError);
        }

        function getAllNotificationsByGPSImeiAndDateOk(object) {
            clearList(opener.globalNotificationHistoryByDates.notificationsList);
            clearDataSource(opener.globalNotificationHistoryByDates.notificationsDataSource, getNotificationsGrid(), true);
            NotificationHistory.openXMLNotificationTrackData(object, opener.globalNotificationHistoryByDates.notificationsList);
            NotificationHistory.loadNotificationTrackDataDataSource(getNotificationsGrid(), opener.globalNotificationHistoryByDates.notificationsList, opener.globalNotificationHistoryByDates.notificationsDataSource);
            responseEnd(getrpvNotificationsPanelUpdateControl());
        }

        function getAllNotificationsByGPSImeiAndDateError(error) {
            responseEnd(getrpvNotificationsPanelUpdateControl());
            objWindowsMessageManager.show_Error(error.get_message(), titles.notifications);
        }

        function getBeginDateSelected() {
            return $find('<%= beginDateSelected.ClientID %>');
        }

        function getEndDateSelected() {
            return $find('<%= endDateSelected.ClientID %>');
        }

        function getrpvNotificationsPanelUpdateControl() {
            return "<%= rpvNotifications.ClientID %>";
        }

        function getNotificationsGrid() {
            return $find("<%= rgNotificationsGrid.ClientID %>").get_masterTableView();
        }

        function requestStart(object) {
            try {
                $find("<%= RadAjaxLoadingPanel1.ClientID%>").show(object);
            }
            catch (e) {
                null;
            }
        }

        function responseEnd(object) {
            try {
                $find("<%= RadAjaxLoadingPanel1.ClientID%>").hide(object);
            }
            catch (e) {
                null;
            }
        }
    </script>
</telerik:RadScriptBlock>
</head>
<body onload="">
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"  EnablePageMethods="true" EnablePartialRendering="true"></telerik:RadScriptManager>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
				<telerik:AjaxSetting AjaxControlID="AjaxControlID1">
					<UpdatedControls>
						<telerik:AjaxUpdatedControl ControlID="Loading" LoadingPanelID="RadAjaxLoadingPanel1" />
					</UpdatedControls>
				</telerik:AjaxSetting>
			</AjaxSettings>
        </telerik:RadAjaxManager>
        
        
        <telerik:RadTabStrip ID="rtsNotifications" runat="server" SelectedIndex="0" MultiPageID="rmpNotifications" ></telerik:RadTabStrip>
        <telerik:RadMultiPage ID="rmpNotifications" runat="server" SelectedIndex="0">
            <telerik:RadPageView ID="rpvNotifications" runat="server">

                <table style="width: 500px; text-align: left">
					<tr>
                        <td>
                            <fieldset>
                                <legend>Seleccione las fechas a Consultar</legend>
                                <telerik:RadDatePicker ID="beginDateSelected" runat="server" DateInput-Label="Fecha Desde" style="text-align: left" Height="24px" Width="200px">
							        <Calendar UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False" ViewSelectorText="x"></Calendar>
			                        <DateInput DateFormat="dd/MM/yyyy" DisplayDateFormat="dd/MM/yyyy" Height="24px" LabelWidth="50%"></DateInput>
		                        </telerik:RadDatePicker>

                                <telerik:RadDatePicker ID="endDateSelected" runat="server" DateInput-Label="Fecha Hasta" style="text-align: left" Height="24px" Width="200px">
							        <Calendar UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False" ViewSelectorText="x"></Calendar>
			                        <DateInput DateFormat="dd/MM/yyyy" DisplayDateFormat="dd/MM/yyyy" Height="24px" LabelWidth="50%"></DateInput>
		                        </telerik:RadDatePicker>
                                <input id="btnGetNotifications" type="button" value="Consultar Notificaciones" onclick="getNotifications();" />
                            </fieldset>                      
                        </td>
                    </tr>
                    <tr>
                        <td>
							<fieldset>
								<legend>Notificaciones</legend>
								<telerik:RadGrid ID="rgNotificationsGrid" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="175px" OnNeedDataSource="rgNotificationsGrid_NeedDataSource"  Width="590px">
									<ClientSettings>
										<Selecting AllowRowSelect="True" />
										<ClientEvents OnRowClick="" />
										<Scrolling AllowScroll="True" UseStaticHeaders="true" />
									</ClientSettings>
									<MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" ClientDataKeyNames="GPSImei, NotificationID" NoMasterRecordsText="No hay Notificaciones registradas">
										<CommandItemSettings ExportToPdfText="Export to PDF" />
										<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
										</RowIndicatorColumn>
										<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
										</ExpandCollapseColumn>
										<Columns>
											<telerik:GridBoundColumn DataField="GPSImei" FilterControlAltText="Filter Description column" HeaderText="GPSImei" UniqueName="GPSImei" Display="false">
											</telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="GPSName" FilterControlAltText="Filter Description column" HeaderText="Name" UniqueName="Name" Visible="true" ItemStyle-Width="150px" HeaderStyle-Width="150px">
											</telerik:GridBoundColumn>
											<telerik:GridBoundColumn DataField="NotificationID" FilterControlAltText="Filter Description column" HeaderText="NotificationID" Display="false">
											</telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="Datetime" FilterControlAltText="Filter Description column" HeaderText="Fecha" Visible="true" ItemStyle-Width="150px" HeaderStyle-Width="150px">
											</telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="NotificationText" FilterControlAltText="Filter Description column" HeaderText="Notificación" Visible="true">
											</telerik:GridBoundColumn>
										</Columns>
									</MasterTableView>
									<FilterMenu EnableImageSprites="true">
									</FilterMenu>
								</telerik:RadGrid>
							</fieldset>
						</td>
                    </tr>
                </table>

            </telerik:RadPageView>
        </telerik:RadMultiPage>

        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default"></telerik:RadAjaxLoadingPanel>
    </form>
</body>
</html>
